#include "widget.h"
#include "ui_widget.h"
#include "teacher.h"
#include "student.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //同一个类之间的型号和槽
    connect(this, &Widget::my_test_signals, this, &Widget::my_slots);
    emit_test_signal();
    //不同类之间的信号和槽
    this->tch = new Teacher(this);
    this->stu = new student(this);
    connect(tch, &Teacher::my_signal, stu, &student::start_study);
    emit_study_signal();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    this->close(); // 关闭窗口的代码
}

void Widget::my_slots()
{
    qDebug() << "我的信号到达了！";
}

void Widget::emit_test_signal()
{
    emit my_test_signals(); // emit关键字发送型号
}

void Widget::emit_study_signal()
{
    emit stu->start_study();
}
